
//1. 引入  路由模块  和  Vue模块 并且使用 use
import Vue from 'vue'

import VueRouter from 'vue-router'


import Home from 'pages/Home.vue'
import ShopCar from 'pages/ShopCar.vue'
import Login from 'pages/Login.vue'
import Register from 'pages/Register.vue'
import Goods from 'pages/Goods.vue'
import Details from 'pages/Details.vue'
import Error from 'pages/Error.vue'


Vue.use(VueRouter)

//2. 创建路由表

// const routes = [{}]  //数组   数组中每一个对象就是一个路由的配置



const routes = [
  {
    path: '/',
    redirect: '/home' //redirect 重定向
  },
  {
    path: '/home',
    component: Home
  },
  {
    path: '/shopcar',
    component: ShopCar 
  },
  {
    path: '/login',
    component: Login,
    name: 'login'
  },
  {
    path: '/register',
    component: Register
  },
  {
    path: '/goods',
    component: Goods
  },
  {
    path: '/details',
    component: Details,
    name: 'details'
  },
  {
    path: '/error',
    component: Error
  },
  {
    path: '**',
    redirect: '/error' //错误匹配 写在路由表最下方
  }
]

//3. 实例化路由

const router = new VueRouter({
  routes, //路由表
  mode: 'history' //如果你配置了history，一定要和后端配合
})

//4. 路由模块的导出

export default router


//5. 在 根实例中注册 路由模块
